package com.ruoyi.StarStudio.Service.Impl;

import com.ruoyi.StarStudio.DAO.UserInfoDAO;
import com.ruoyi.StarStudio.Entity.UserInfo;
import com.ruoyi.StarStudio.Service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    UserInfoDAO userInfoDAO;

    @Override
    public List<UserInfo> findUserInfoList(UserInfo userInfo) {
        return userInfoDAO.findUserInfoList(userInfo);
    }

    @Override
    public void UserInfoSave(UserInfo userInfo) {
        userInfo.setFirst_login_time(new Timestamp(new Date().getTime()));
        userInfo.setLast_login_time(new Timestamp(new Date().getTime()));
        userInfoDAO.UserInfoAdd(userInfo);
    }

    @Override
    public int findByCondition(UserInfo userInfo) {
        return userInfoDAO.findByCondition(userInfo);
    }

    @Override
    public void updateUserInfo(UserInfo userInfo) {
        userInfoDAO.updateUserInfo(userInfo);
    }

    @Override
    public UserInfo findByUserId(long id) {
        return userInfoDAO.findByUser_id(id);
    }

    @Override
    public long findAllRecordNumber() {
        return userInfoDAO.findAllRecordNumber();
    }

    /**
     * 定时更新用户信息
     * 每天00:00:00重置每天的统计信息为 0
     */
    @Scheduled(cron = "${time.cron}")
    public void UserInfoAutoUpdate(){
        userInfoDAO.updateUserInfoPerDay();
    }
}
